<template>
  <div>
    <!-- 筛选项 -->
    <el-form v-show="showSearch" :model="searchForm" :inline="true" class="demo-form-inline" label-suffix="："
      size="small">
      <el-form-item label="处置简称">
        <el-input v-model="searchForm.programName" placeholder="请输入" clearable></el-input>
      </el-form-item>
      <el-form-item label="设施类型">
        <el-cascader filterable v-model="searchForm.facilityTypeUuid" :options="sheshileixingOptions"
          @change="selSheShi" :props="{ children: 'list', value: 'facilityTypeUuid', label: 'facilityTypeName' }"
          clearable></el-cascader>
      </el-form-item>
      <el-form-item label="构件/设备类型">
        <el-select filterable v-model="searchForm.componentTypeUuid" placeholder="请选择" clearable>
          <el-option v-for="item in searchgoujianOptions" :key="item.componentTypeUuid" :label="item.componentTypeName"
            :value="item.componentTypeUuid" />
        </el-select>
      </el-form-item>
      <el-form-item label="计划类型">
        <el-cascader filterable style="width:100%" v-model="searchForm.planTypeUuid" :options="jihualeiixngOptions"
          @change="selJiHua" :props="{ children: 'list', value: 'planTypeUuid', label: 'planTypeName' }"
          clearable></el-cascader>
      </el-form-item>
      <el-form-item label="病害类型">
        <el-select filterable v-model="searchForm.diseaseTypeUuid" placeholder="请选择" clearable>
          <el-option v-for="item in binghaiOptions" :key="item.oftenUuid" :label="item.oftenName"
            :value="item.oftenUuid" />
        </el-select>
      </el-form-item>
    </el-form>

    <!-- 操作 -->
    <div class="dis-o-between operate-line">
      <div>
        <el-button icon="el-icon-plus" plain type="primary" @click="addItem" size="small">新增</el-button>
        <el-button icon="el-icon-search" type="primary" @click="reqTableData(1)" size="small">查询</el-button>
        <el-button icon="el-icon-refresh" @click="resetReq()" size="small">重置</el-button>
      </div>
      <RightToolbar :showSearch.sync="showSearch" @queryTable="reqTableData(1)"></RightToolbar>
    </div>

    <!-- 表格 -->
    <el-table :data="tableData">
      <el-table-column v-for="(item, index) in tableTitle" :key="index" :prop="item.prop" :label="item.label"
        :type="item.type" :fixed="item.fixed ? item.fixed : null" :align="item.align" :width="item.width">
        <template slot-scope="scope">
          {{ item.prop === 'isApproval' ? scope.row.isApproval == 1 && scope.row.isApproval ? '是' : '否' :
            scope.row[item.prop] }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="200px" align="center">
        <template #default='scope'>
          <div style="text-align: center;">
            <el-button type="text" @click="editRow(scope.row)">编辑
            </el-button>
            <el-button type="text" @click="delRow(scope.row)">删除
            </el-button>
            <el-button type="text" @click="gongxuChaKan(scope.row.programUuid)">工序详情
            </el-button>
          </div>
          <div>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <paginationCom :pagination="pagination" @handleSizeChange="handleSizeChange"
      @handleCurrentChange=handleCurrentChange>
    </paginationCom>
    <!-- 新增方案标准 -->
    <el-dialog v-dialogDrag :title="title" :visible.sync="fangAnShow" :destroy-on-close='true' width="600px">
      <el-form :model="addFangAn" :rules="fromRule" ref="addFangAn" label-width="130px" class="demo-ruleForm">
        <el-form-item label="处置简称" prop="programName">
          <el-input v-model="addFangAn.programName" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="所属设施类型" prop="facilityTypeUuid">
          <el-cascader style="width:100%" v-model="addFangAn.facilityTypeUuid"
            :props="{ children: 'list', value: 'facilityTypeUuid', label: 'facilityTypeName' }"
            :options="sheshileixingOptions" clearable></el-cascader>
        </el-form-item>
        <el-form-item label="部件类型" prop="partsUuid">
          <el-select @change="getGouJian" style="width:100%" filterable v-model="addFangAn.partsUuid" placeholder="请选择"
            clearable>
            <el-option v-for="item in bujianOptions" :key="item.partsUuid" :label="item.partsName"
              :value="item.partsUuid" />
          </el-select>
        </el-form-item>
        <el-form-item label="构件类型" prop="componentTypeUuid">
          <el-select style="width:100%" v-model="addFangAn.componentTypeUuid" placeholder="请选择" filterable clearable>
            <el-option v-for="item in goujianOptions" :key="item.componentTypeUuid" :label="item.componentTypeName"
              :value="item.componentTypeUuid" />
          </el-select>
        </el-form-item>
        <el-form-item label="计划类型" prop="planTypeUuid">
          <el-cascader style="width:100%" v-model="addFangAn.planTypeUuid" :options="jihualeiixngOptions"
            :props="{ checkStrictly: true, children: 'list', value: 'planTypeUuid', label: 'planTypeName' }"
            clearable></el-cascader>
        </el-form-item>
        <el-form-item label="病害类型" prop="diseaseTypeUuid">
          <el-select style="width: 100%;" v-model="addFangAn.diseaseTypeUuid" placeholder="请选择" filterable clearable>
            <el-option v-for="item in binghaiOptions" :key="item.oftenUuid" :label="item.oftenName"
              :value="item.oftenUuid" />
          </el-select>
        </el-form-item>
        <el-form-item label="风险等级" prop="riskLevel">
          <el-select style="width:100%" v-model="addFangAn.riskLevel" placeholder="请选择" filterable clearable>
            <el-option v-for="item in fengxianOptions" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="工序审核" prop="isApproval">
          <el-switch @change="addFangAnGongXuSwitchChange" v-model="addFangAnIsApproval" active-color="#409eff"
            inactive-color="#dcdfe6">
          </el-switch>
          {{ addFangAnIsApproval == 0 ? '否' : '是' }}
        </el-form-item>
        <el-form-item label="标准施工图" prop="programImage">
          <imgUpload ref="imgUpload" :limit="2" :imageUrl="addFangAn.programImage"></imgUpload>
        </el-form-item>
        <el-form-item label="技术交底" prop="technicalDisclosure">
          <el-input v-model="addFangAn.technicalDisclosure" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="安全交底" prop="safetyDisclosure">
          <el-input v-model="addFangAn.safetyDisclosure" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="完善建议" prop="perfectSuggest">
          <el-input v-model="addFangAn.perfectSuggest" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="对应国标" prop="nationalStandard">
          <el-input v-model="addFangAn.nationalStandard" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="工时（小时）" prop="programHour">
          <el-input placeholder="请输入" type="number"
            oninput="if(isNaN(value)) { value = null } if(value.indexOf('.')>0){value=value.slice(0,value.indexOf('.')+2)}"
            v-model="addFangAn.programHour"></el-input>
        </el-form-item>
        <el-form-item label="计划材料" prop="planeMaterial">
          <el-input v-model="addFangAn.planeMaterial" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="计划设备" prop="planeEquipment">
          <el-input v-model="addFangAn.planeEquipment" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="预算详情" prop="detailedBudget">
          <el-input v-model="addFangAn.detailedBudget" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="预算（元）" prop="budget">
          <el-input placeholder="请输入" type="number"
            oninput="if(isNaN(value)) { value = null } if(value.indexOf('.')>0){value=value.slice(0,value.indexOf('.')+3)}"
            v-model="addFangAn.budget"></el-input>
        </el-form-item>
        <el-form-item label="标准人数" prop="persionNum">
          <el-input v-model="addFangAn.persionNum" placeholder="请输入" clearable></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="fangAnShow = false">取 消</el-button>
        <el-button @click="addContinue('addFangAn')" v-show="this.title == '新增' ? true : false">确定并继续</el-button>
        <el-button type="primary" @click="addFangAnSub('addFangAn')">确 定
        </el-button>
      </div>
    </el-dialog>
    <!-- 工序详情 -->
    <el-dialog v-dialogDrag title="工序详情" :visible.sync="gongXuShow" :destroy-on-close='true' width="1000px">
      <el-form :inline="true" label-width="110px">
        <el-form-item>
          <el-button type="primary" @click="addGongXuItem">新增工序
          </el-button>
          <el-button type="primary" @click="paixuSub">确认排序
          </el-button>
        </el-form-item>
      </el-form>
      <el-table id="dsadasdas" row-key="id" :data="gongXuTable" border style="width: 100%;">
        <el-table-column type="index" label="序号" align="center" width="50px"></el-table-column>
        <el-table-column prop="procedureName" label="工序名称" align="center"></el-table-column>
        <el-table-column prop="procedureExplain" label="工序说明" align="center"></el-table-column>
        <el-table-column prop="isApproval" label="是否审核" width="120" align="center">
          <template #default='scope'>
            <div>{{ scope.row.isApproval == 1 && scope.row.isApproval ? '是' : '否' }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="procedureHour" label="工序工时" align="center"></el-table-column>
        <el-table-column prop="procedureValue" label="工序计价" align="center"></el-table-column>
        <el-table-column prop="isSign1" label="工序标注" align="center"></el-table-column>
        <el-table-column label="操作" min-width="120px" align="center">
          <template #default='scope'>
            <el-button type="text" @click="editGongXuRow(scope.row)">编辑
            </el-button>
            <el-button type="text" @click="delGongXuRow(scope.row)">删除
            </el-button>
            <el-button type="text" @click="gongxubiaozhuRow(scope.row)">工序标注
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 新增编辑工序 -->
    <el-dialog v-dialogDrag title="新增编辑工序" :visible.sync="addGongXuShow" :destroy-on-close='true' width="450px">
      <el-form :model="addGongXu" ref="addGongXu" label-width="160px" class="demo-ruleForm">
        <el-form-item label="工序名称" :rules="{ required: true, message: '工序名称不能为空', trigger: 'blur' }"
          prop="procedureName">
          <el-input v-model="addGongXu.procedureName" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="工序说明" :rules="{ required: true, message: '工序说明不能为空', trigger: 'change' }"
          prop="procedureExplain">
          <el-input v-model="addGongXu.procedureExplain" placeholder="请输入" clearable></el-input>
        </el-form-item>
        <el-form-item label="工序工时（小时）" :rules="{ required: true, message: '工序工时（小时）不能为空', trigger: 'blur' }"
          prop="procedureHour">
          <el-input placeholder="请输入" type="number"
            oninput="if(isNaN(value)) { value = null } if(value.indexOf('.')>0){value=value.slice(0,value.indexOf('.')+3)}"
            v-model="addGongXu.procedureHour"></el-input>
        </el-form-item>
        <el-form-item label="工序审核" prop="isApproval">
          <el-switch @change="addGongXuSwitchChange" v-model="addGongXuIsApproval" active-color="#409eff"
            inactive-color="#dcdfe6">
          </el-switch>
          {{ addGongXuIsApproval == 0 ? '否' : '是' }}
        </el-form-item>
        <el-form-item label="工序计价（元）" :rules="{ required: true, message: '工序计价（元）不能为空', trigger: 'blur' }"
          prop="procedureValue">
          <el-input placeholder="请输入" type="number"
            oninput="if(isNaN(value)) { value = null } if(value.indexOf('.')>0){value=value.slice(0,value.indexOf('.')+3)}"
            v-model="addGongXu.procedureValue"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="addGongXuShow = false">取 消</el-button>
        <el-button type="primary" @click="addGongXuSub('addGongXu')">确 定
        </el-button>
      </div>
    </el-dialog>
    <!--    编辑工序标注-->
    <el-dialog v-dialogDrag title="工序标注" :visible.sync="gongXuBiaoZhuShow" :destroy-on-close='true' width="400px">
      <el-form :model="addGongXu" ref="addGongXu" label-width="100px" class="demo-ruleForm">
        <el-form-item label="工序标注" :rules="{ required: true, message: '工序标注不能为空', trigger: 'blur' }" prop="isSign">
          <el-select v-model="addGongXu.isSign" placeholder="请选择" filterable clearable>
            <el-option v-for="item in gongxubiaozhunOptions" :key="item.value" :label="item.label"
              :value="item.value" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="gongXuBiaoZhuShow = false">取 消</el-button>
        <el-button type="primary" @click="addGongXuSub('addGongXu')">确 定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import imgUpload from '@/components/upLoad/imgUpload.vue';
import Sortable from 'sortablejs';
export default {
  name: 'scheme',
  data() {
    return {
      showSearch: true,
      // 分页器
      pagination: {
        total: 0,
        per_page: 10,
        from: 1,
        to: 0,
        current_page: 1, //当前页数
      },
      tableData: [],
      tableTitle: [
        { prop: 'programName', label: '处置简称', width: '', align: 'center', fixed: "", type: "" },
        { prop: 'facilityTypeName', label: '所属设施类型', width: '120', align: 'center', fixed: "", type: "" },
        { prop: 'componentTypeName', label: '构件/设备类型', width: '120', align: 'center', fixed: "", type: "" },
        { prop: 'planTypeName', label: '计划类型', width: '120', align: 'center', fixed: "", type: "" },
        { prop: 'diseaseTypeName', label: '病害类型', width: '120', align: 'center', fixed: "", type: "" },
        { prop: 'isApproval', label: '是否审核', width: '', align: 'center', fixed: "", type: "" },
        { prop: 'jlUnit', label: '工时', width: '', align: 'center', fixed: "", type: "" },
        { prop: 'riskLevel', label: '风险等级', width: '', align: 'center', fixed: "", type: "" },
        { prop: 'budget', label: '预算', width: '', align: 'center', fixed: "", type: "" },
        { prop: 'detailedBudget', label: '计价详情', width: '', align: 'center', fixed: "", type: "" },
        { prop: 'planeMaterial', label: '计划材料', width: '', align: 'center', fixed: "", type: "" },
        { prop: 'planeEquipment', label: '计划设备', width: '', align: 'center', fixed: "", type: "" },
        { prop: 'persionNum', label: '标准人数', width: '', align: 'center', fixed: "", type: "" },
        // { prop: 'safetyDisclosure', label: '技术交底', width: '', align: 'center', fixed: "", type: "" },
        // { prop: 'safetyDisclosure', label: '安全交底', width: '', align: 'center', fixed: "", type: "" },
        // { prop: 'perfectSuggest', label: '建议完善', width: '', align: 'center', fixed: "", type: "" },
        // { prop: 'nationalStandard', label: '对应国标', width: '', align: 'center', fixed: "", type: "" },
      ],



      title: "",
      addVisible: false,
      fromRule: {
        programName: [
          { required: true, message: '处置简称不能为空', trigger: 'blur' }
        ],
        partsUuid: [
          { required: true, message: '部件类型不能为空', trigger: 'change' }
        ],
        componentTypeUuid: [
          { required: true, message: '构件类型不能为空', trigger: 'change' }
        ],
        planTypeUuid: [
          { required: true, message: '计划类型不能为空', trigger: 'change' }
        ],
        diseaseTypeUuid: [
          { required: true, message: '病害类型不能为空', trigger: 'change' }
        ],
        riskLevel: [
          { required: true, message: '风险等级不能为空', trigger: 'change' }
        ],
      },
      addFangAn: {
        isApproval: 0,
      },//新增方案标准表单
      addGongXu: {
        programUuid: '',
        isApproval: 0,
      },//新增编辑工序详情
      fangAnShow: false,
      gongXuShow: false,
      addGongXuShow: false,
      searchForm: {
        pageNum: 1,
        pageSize: 10,
        componentTypeUuid: '',
        diseaseTypeUuid: '',
        facilityTypeUuid: '',
        planTypeUuid: '',
        programName: '',
      },
      gongXuTable: [],
      fengxianOptions: [
        { label: '一级', value: 1 },
        { label: '二级', value: 2 },
        { label: '三级', value: 3 },
        { label: '四级', value: 4 },
      ],
      gongxubiaozhunOptions: [
        { label: '施工前', value: 0 },
        { label: '施工中', value: 1 },
        { label: '施工后', value: 2 },
      ],
      // 设施分类筛选项
      sheshileixingOptions: [],
      // 构件类型筛选项
      goujianOptions: [],
      searchgoujianOptions: [],
      // 病害类型筛选项
      binghaiOptions: [],
      // 部件类型筛选项
      bujianOptions: [],
      // 计划类型筛选项
      jihualeiixngOptions: [],
      rowProgramUuid: '',
      gongXuBiaoZhuShow: false,
      addFangAnIsApproval: false,
      addGongXuIsApproval: false,
    };
  },
  props: {},

  components: { imgUpload },

  created() { },

  mounted() {
    this.reqTableData(1)
    this.initData()
    this.getComponentTypeByObj()
  },

  beforeDestroy() { },

  methods: {
    // 重置事件
    resetReq() {
      this.searchForm = {
        pageNum: 1,
        pageSize: 10,
        componentTypeUuid: '',
        diseaseTypeUuid: '',
        facilityTypeUuid: '',
        planTypeUuid: '',
        programName: '',
      };
      this.pagination = { total: 0, per_page: 10, from: 1, to: 0, current_page: 1, };
      this.reqTableData(1);
    },
    addFangAnGongXuSwitchChange(val) {
      if (val) {
        this.addFangAn.isApproval = 1
      } else {
        this.addFangAn.isApproval = 0
      }
    },
    addGongXuSwitchChange(val) {
      if (val) {
        this.addGongXu.isApproval = 1
      } else {
        this.addGongXu.isApproval = 0
      }
      // console.log(val)
    },
    initData() {
      // 获取设施类型筛选项
      this.sendPost('/facilityType/getFacilityTypeByObj', {}).then(res => {
        this.sheshileixingOptions = res.data.list
        this.sheshileixingOptions.forEach((item1) => {
          if (item1.list.length !== 0) {
            item1.list.forEach(item2 => {
              if (item2.list.length !== 0) {
                item2.list.forEach(item3 => {
                  if (item3.list.length !== 0) {
                    delete item3.list
                  } else {
                    delete item3.list
                  }
                })
              } else {
                delete item2.list
              }
            })
          } else {
            delete item1.list
          }
        })
      })
      // 获取计划类型筛选项
      this.sendPost('/planType/getPlanTypeByObj', {}).then(res => {
        this.jihualeiixngOptions = res.data.list
        this.jihualeiixngOptions.forEach((item1) => {
          if (item1.list.length !== 0) {
            item1.list.forEach(item2 => {
              if (item2.list.length !== 0) {
                item2.list.forEach(item3 => {
                  if (item3.list.length !== 0) {
                    delete item3.list
                  } else {
                    delete item3.list
                  }
                })
              } else {
                delete item2.list
              }
            })
          } else {
            delete item1.list
          }
        })
      })
      // 查询部件类型表格
      this.sendPost('/parts/getPartsByObj', {}).then(res => {
        this.bujianOptions = res.data.list;
      })
      // 获取病害类型筛选项
      this.sendPost('/OftenType/getSonOftenTypeParent', { oftenName: '病害类型' }).then(res => {
        this.binghaiOptions = res.data.list;
      })
    },
    // 初始请求
    reqTableData(page) {
      // 获取方案标准表格
      if (page) {
        this.pagination.current_page = page;
      }
      this.loading = true;
      let data = {
        ...this.searchForm,
        pageNum: this.pagination.current_page,
        pageSize: this.pagination.per_page,
      };
      this.sendPost('/programBz/getProgramBzByObj', data).then(res => {
        this.tableData = res.data.list;
        this.pagination.total = res.data.total
        this.loading = false;
      })
    },
    // 新增设施分类
    addItem() {
      this.title = "新增",
        this.addFangAn = { programImage: [], isApproval: 0 }
      // console.log(this.addFangAn)
      this.fangAnShow = true;
    },
    // 新增工序
    addGongXuItem() {
      this.addGongXu = {
        isApproval: 0,
      }
      this.addGongXuIsApproval = false,
        this.addGongXuShow = true;
    },
    //行拖拽
    rowDrop() {
      const tbody = document.querySelector('#dsadasdas .el-table__body-wrapper tbody')
      Sortable.create(tbody, {
        onEnd: ({ newIndex, oldIndex }) => {
          if (this.gongXuTable && this.gongXuTable.length > 0) {
            const currRow = this.gongXuTable.splice(oldIndex, 1)[0];
            this.gongXuTable.splice(newIndex, 0, currRow);
            // console.log(this.gongXuTable)
          }
        }
      })
    },
    // 编辑
    editRow(row) {
      this.title = "编辑";
      this.addFangAn = { programImage: [], }
      if (row.isApproval !== null && row.isApproval !== '' && row.isApproval !== 0) {
        this.addFangAnIsApproval = true
      } else {
        this.addFangAnIsApproval = false
      }
      let data = JSON.parse(JSON.stringify(row))
      if (data.partsUuid) {
        this.sendPost('/componentType/getComponentTypeByObj', { partsUuid: data.partsUuid }).then(res => {
          this.goujianOptions = res.data.list;
        })
      }
      let b = [];
      if (data.programImage) {
        let a = row.programImage.split(',')
        b = a.map(item => {
          return {
            url: item
          }
        })
      }
      this.$set(data, 'programImage', b);
      this.addFangAn = data;
      this.fangAnShow = true;
      this.$refs.addFangAn.clearValidate()
      this.$forceUpdate();
    },
    // 编辑工序
    editGongXuRow(row) {
      this.addGongXu = {};
      this.addGongXu = JSON.parse(JSON.stringify(row))
      if (row.isApproval !== null && row.isApproval !== '' && row.isApproval !== 0) {
        this.addGongXuIsApproval = true
      } else {
        this.addGongXuIsApproval = false
      }
      this.addGongXuShow = true
    },
    // 工序标注
    gongxubiaozhuRow(row) {
      // console.log(row);
      this.addGongXu = {};
      if (row.isSign == -1) {
        row.isSign = ''
      }
      this.addGongXu = JSON.parse(JSON.stringify(row))
      this.gongXuBiaoZhuShow = true
    },
    // 点击工序详情查看
    gongxuChaKan(programUuid) {
      this.gongXuShow = true;
      this.rowProgramUuid = programUuid;
      // 获取工序详情表格
      this.sendPost('/programProcedure/getProgramProcedureByObj', { programUuid: programUuid }).then(res => {
        this.gongXuTable = res.data.list || [];
        this.gongXuTable.forEach(ele => {
          if (ele.isSign == 0) {
            ele.isSign1 = '施工前'
          } else if (ele.isSign == 1) {
            ele.isSign1 = '施工中'
          } else if (ele.isSign == 2) {
            ele.isSign1 = '施工后'
          }
        })
        //使每次都可以拖拽
        this.$nextTick(() => {
          setTimeout(() => {
            this.rowDrop();
          }, 100)
        })
      })
    },
    // 部件的change事件 动态获取构件
    getGouJian(val) {
      // 获取构件类型筛选项
      this.sendPost('/componentType/getComponentTypeByObj', { partsUuid: val }).then(res => {
        this.goujianOptions = res.data.list;
        this.$set(this.addFangAn, 'componentTypeUuid', '');
      })
    },
    // 新增方案确定事件
    addFangAnSub(data) {
      this.$refs[data].validate((valid) => {
        if (valid) {
          // 给主计划类型uuid和子计划赋值
          if (this.addFangAn.planTypeUuid.constructor === Array) {
            this.addFangAn.parentPlanTypeUuid = this.addFangAn.planTypeUuid[0];
            this.addFangAn.planTypeUuid = this.addFangAn.planTypeUuid[1];
          }
          // 给设施类型uuid赋值
          // console.log(this.addFangAn.facilityTypeUuid);
          // if (this.addFangAn.facilityTypeUuid.constructor === Array) {
          //   this.addFangAn.facilityTypeUuid = this.addFangAn.facilityTypeUuid[1];
          // }
          if (this.addFangAn.facilityTypeUuid) {
            this.addFangAn.facilityTypeUuid = this.addFangAn.facilityTypeUuid[1];
          }
          // 查部件类型名称
          this.bujianOptions.forEach(ele => {
            if (ele.partsUuid == this.addFangAn.partsUuid) {
              this.addFangAn.partsName = ele.partsName;
            }
          })
          // 查构件类型名称
          this.goujianOptions.forEach(ele => {
            if (ele.componentTypeUuid == this.addFangAn.componentTypeUuid) {
              this.addFangAn.componentTypeName = ele.componentTypeName;
            }
          })
          // 查病害类型的名称
          this.binghaiOptions.forEach(ele1 => {
            if (ele1.oftenUuid == this.addFangAn.diseaseTypeUuid) {
              this.addFangAn.diseaseTypeName = ele1.oftenName;
            }
          })
          // 查计划类型名称
          this.jihualeiixngOptions.forEach(ele2 => {
            if (ele2.planTypeUuid == this.addFangAn.parentPlanTypeUuid) {
              this.addFangAn.parentPlanTypeName = ele2.planTypeName;
            }
          })
          this.jihualeiixngOptions.forEach(ele3 => {
            if (ele3.list != undefined) {
              ele3.list.forEach(ele4 => {
                if (ele4.planTypeUuid == this.addFangAn.planTypeUuid) {
                  this.addFangAn.planTypeName = ele4.planTypeName;
                }
              })
            }
          })
          // 查所属设施类型名称
          this.sheshileixingOptions.forEach(ele5 => {
            if (ele5.list != undefined) {
              ele5.list.forEach(item => {
                if (item.facilityTypeUuid == this.addFangAn.facilityTypeUuid) {
                  this.addFangAn.facilityTypeName = item.facilityTypeName
                }
              })
            }
          })
          let data = JSON.parse(JSON.stringify(this.addFangAn))
          data.programImage = this.img_data(this.addFangAn.programImage)
          this.addVisible = false;
          this.sendPost('/programBz/insertOrUpdateProgramBz', data).then(res => {
            if (res.errcode == 0) {
              this.suc({ message: res.errmsg })
              this.reqTableData();
              this.addFangAn = { programImage: [], }
            } else {
              this.err({ message: res.errmsg })
            }
          });
          this.fangAnShow = false;
        } else {
          // console.log('请填写');
          return false;
        }
      });
    },
    // 图片数据处理
    img_data(data) {
      let image = []
      data.map(item => {
        image.push(item.url)
      })
      return image.toString()
    },
    // 新增工序确定事件
    addGongXuSub(data) {
      this.$refs[data].validate((valid) => {
        if (valid) {
          this.addGongXuShow = false;
          this.gongXuBiaoZhuShow = false;
          this.addGongXu.programUuid = this.rowProgramUuid;
          this.sendPost('/programProcedure/insertOrUpdateProgramProcedure', this.addGongXu).then(res => {
            if (res.errcode == 0) {
              this.suc({ message: res.errmsg })
              this.gongxuChaKan(this.rowProgramUuid);
              this.addGongXu = {};
            } else {
              this.err({ message: res.errmsg })
            }
          })
        } else {
          // console.log('请填写');
          return false;
        }
      });
    },
    // 确认排序的事件
    paixuSub() {
      let ids = [];
      for (var i = 0; i < this.gongXuTable.length; i++) {
        ids.push({ id: this.gongXuTable[i].id, sort: i + 1 })
      }
      this.sendPost('/programProcedure/getSort', { procedureList: ids }).then(res => {
        if (res.errcode == 0) {
          this.suc({ message: res.errmsg })
          this.gongxuChaKan(this.rowProgramUuid);
        } else {
          this.err({ message: res.errmsg })
        }
      })
    },
    // 删除
    delRow(row) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.sendGet('/programBz/deleteProgramBz', { id: row.id }).then(res => {
          if (res.errcode == 0) {
            this.suc({ message: res.errmsg })
            this.reqTableData()
          } else {
            this.err({ message: res.errmsg })
          }
        })
      }).catch(() => {
        // this.$message({ type: 'info', message: '已取消删除' });
      });
    },
    // 删除工序
    delGongXuRow(row) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.sendGet('/programProcedure/delete', { id: row.id }).then(res => {
          if (res.errcode == 0) {
            this.suc({ message: res.errmsg })
            this.gongxuChaKan(this.rowProgramUuid);
          } else {
            this.err({ message: res.errmsg })
          }
        })
      }).catch(() => {
        // this.$message({ type: 'info', message: '已取消删除' });
      });
    },
    // 确定并新增
    addContinue(refForm) {
      this.addFangAnSub(refForm);
      this.addFangAn = {};
      this.fangAnShow = true;
    },
    // 设施分类筛选项change事件
    selSheShi(val) {
      this.searchForm.facilityTypeUuid = val[1];
    },
    selJiHua(val) {
      this.searchForm.planTypeUuid = val[1];
    },
    // 分页器----新每页条数
    handleSizeChange(val) {
      this.pagination.per_page = val;
      this.reqTableData(1);
    },
    // 分页器-----新当前页
    handleCurrentChange(val) {
      this.pagination.current_page = val;
      this.reqTableData();
    },


    getComponentTypeByObj() {
      this.sendPost('/componentType/getComponentTypeByObj', {}).then(res => {
        this.searchgoujianOptions = res.data.list;
      })
    }

  },

  computed: {},

  watch: {},

  directives: {},

  filters: {}
};
</script>

<style scoped lang="scss"></style>
